<div class="page-container" v-cloak>
    <el-card>
        <template #header>
            <div class="breadcrumb">
                <el-breadcrumb separator="/">
                    <el-breadcrumb-item>套餐列表</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
        </template>
        <div>
            <el-form :inline="true">

                <el-form-item>
                    <el-input v-model="where.name" placeholder="套餐名称"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-select filterable v-model="where.type" placeholder="套餐类型">
                        <el-option label="不限" :value=""></el-option>
                        <el-option label="正常" :value="0"></el-option>
                        <el-option label="加时" :value="1"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-link>
                        <el-button type="primary" @click="searchEvent">查询</el-button>
                    </el-link>
                    <el-link href="{:url('admin/package/edit')}">
                        <el-button type="primary">新增</el-button>
                    </el-link>
                </el-form-item>
            </el-form>
        </div>
        <div>
            <el-table

                    :data="data_list"
                    style="width: 100%">
                <el-table-column
                        prop="package_id"
                        label="ID"
                        min-width="80">
                </el-table-column>
                <el-table-column
                        prop="name"
                        label="套餐名称"
                        min-width="180">
                </el-table-column>
                <el-table-column
                        prop="price"
                        min-width="180"
                        label="套餐价格">
                </el-table-column>
                <el-table-column label="套餐类型">

                    <template v-slot:default="scope">

                        <!-- 使用 scope.row 来访问当前行的数据 -->

                        <span v-if="scope.row.type === 1">加时套餐</span>
                        <span v-else style="color: #529b2e">正常套餐</span>

                    </template>

                </el-table-column>
                <el-table-column label="状态">

                    <template v-slot:default="scope">

                        <!-- 使用 scope.row 来访问当前行的数据 -->

                        <span v-if="scope.row.status === 1" style="color: #529b2e">显示</span>
                        <span v-else>隐藏</span>

                    </template>

                </el-table-column>
                <el-table-column
                        prop="created_at"
                        width="160"
                        label="创建时间">
                </el-table-column>
                <el-table-column
                        align="center"
                        min-width="180"
                        label="操作">
                    <template #default="{row}">
                        <el-link :href="'{:url('admin/package/edit')}?package_id='+row.package_id">
                            <el-button type="primary">编辑</el-button>
                        </el-link>
                        <el-link>
                            <el-button @click="deleteEvent(row)" type="danger">删除</el-button>
                        </el-link>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        background
                        layout="prev, pager, next"
                        :total="total_num"
                        :current-page="current_page"
                        :page-size="per_page"
                        @current-change="currentChangeEvent"
                >
                </el-pagination>
            </div>
        </div>
    </el-card>
</div>

<script>
    const App = {
        data() {
            return {
                is_init_list: true,
                role_list: [],
                where: {},
            }
        },
        methods: {
            GetList() {
                this.httpGet("{:url('admin/package/index/lists')}", {
                    page: this.current_page,
                    ...this.where
                }).then(res => {
                    let {lists = {}, role_list = []} = res.data
                    this.role_list = role_list
                    this.handRes(lists)
                })
            },
            deleteEvent({package_id}) {
                this.$confirm('是否确认删除该管理员？', '提示').then(() => {
                    this.httpDelete("{:url('admin/package/delete')}/" + package_id, {}).then(res => {
                        if (res.status) {
                            this.$message.success(res.msg)
                            this.GetList()
                        }
                    })
                }).catch(err => {
                })
            },
            searchEvent() {
                this.GetList()
            }
        }
    }
</script>